package com.dqp.cslggroup.SubjectView;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.dqp.cslggroup.R;

public class WeekAdapter extends BaseAdapter {
    //图片id数组
    private String[] imgs = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"};
    private int[] flag;
    //上下文对象
    Context context;

    //构造方法
    WeekAdapter(Context context, int[] flag) {
        this.context = context;
        this.flag = flag;
    }

    //获得数量
    public int getCount() {
        return imgs.length;
    }

    //获得当前选项
    public Object getItem(int item) {
        return item;
    }

    //获得当前选项id
    public long getItemId(int id) {
        return id;
    }

    @Override

    //创建View方法
    public View getView(int position, View convertView, ViewGroup parent) {
        Button textView;
        if (convertView == null) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.button_view, parent, false);
            textView = view.findViewById(R.id.button_g);
            if (flag[position] == 1) textView.setBackgroundColor(Color.WHITE);
            else textView.setBackground(context.getDrawable(R.drawable.btn_circle));

        } else {
            textView = (Button) convertView;
        }
        //为ImageView设置图片资源
        textView.setText(imgs[position]);
        return textView;
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
    }
}
